package com.bianxianmao.lastknow.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bianxianmao.R;
import com.bianxianmao.lastknow.bean.LastKnowBean;
import com.bumptech.glide.Glide;

import java.util.List;

import static com.igexin.sdk.GTServiceManager.context;

/**
 * Created by Administrator on 2017/8/14.
 */

public class MyListViewAdapter extends BaseAdapter {
    private List<LastKnowBean.ReturnValueBean> bean;
    private Context mContext;

    public MyListViewAdapter(List list, Context mContext) {
        this.bean = list;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return bean.size();
    }

    @Override
    public Object getItem(int position) {
        return bean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder;
        if (view == null) {
            view = View.inflate(context, R.layout.lastknow_item1, null);
            viewHolder = new ViewHolder();
            viewHolder.goodimg = (ImageView) view.findViewById(R.id.goodimg);
            viewHolder.periodsNumber = (TextView) view.findViewById(R.id.periodsNumber);
            viewHolder.winMemberName = (TextView) view.findViewById(R.id.winMemberName);
            viewHolder.winMemberBuyCount = (TextView) view.findViewById(R.id.winMemberBuyCount);
            viewHolder.winNumber = (TextView) view.findViewById(R.id.winNumber);
            viewHolder.dbOpenTime = (TextView) view.findViewById(R.id.dbOpenTime);
            view.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(bean.get(position).getImg1()).into(viewHolder.goodimg);
        viewHolder.winMemberName.setText(bean.get(position).getWinMemberName());
        viewHolder.periodsNumber.setText(bean.get(position).getPeriodsNumber() + "");
        if (bean.get(position).getWinMemberBuyCount() != -1) {
            viewHolder.winMemberBuyCount.setText(bean.get(position).getWinMemberBuyCount() + "");
        } else {
            viewHolder.winMemberBuyCount.setText(0 + "");
        }
        if (bean.get(position).getWinNumber() != null) {
            viewHolder.winNumber.setText(bean.get(position).getWinNumber() + "");
        } else {
            viewHolder.winNumber.setText("");
        }
        if (bean.get(position).getDbOpenTime() != null) {
            viewHolder.dbOpenTime.setText(bean.get(position).getDbOpenTime() + "");
        } else {
            viewHolder.dbOpenTime.setText("");
        }
        return view;

    }

    class ViewHolder {
        private ImageView goodimg;
        private TextView periodsNumber;
        private TextView winMemberName;
        private TextView winMemberBuyCount;
        private TextView winNumber;
        private TextView dbOpenTime;

    }


}
